home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / PublicDomain / Anwendungen / db3.6-beta-src / dbGUI.c < prev    next >
C/C++ Source or Header  |  1998-03-14  |  48KB  |  1,113 lines

  1. /*
  2.  *  GUI Designed by : David Ekholm, Datadosen
  3.  */
  4.  
  5. #include <stdlib.h>     /* atoi() */
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/intuitionbase.h>
  10. #include <intuition/screens.h>  /* DrawInfo */
  11. #include <intuition/classes.h>
  12. #include <intuition/classusr.h>
  13. #include <intuition/imageclass.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <gadgets/textfield.h>
  16.  
  17. #include <intuition/sghooks.h> /* struct SGWork here */
  18. #include <workbench/workbench.h>        /* For AppWindow */
  19. #include <libraries/gadtools.h>
  20. #include <libraries/commodities.h> /* This has a nice qualifier #define */
  21. #include <libraries/iffparse.h>
  22.  
  23. #include <graphics/displayinfo.h>
  24. #include <graphics/gfxbase.h>
  25. #include <graphics/text.h>              /* For my TextAttr struct */
  26. #include <graphics/rastport.h>
  27. #include <utility/hooks.h>              /* For my stringhook */
  28.  
  29. #include <proto/wb.h>                           /* For AppWindow */
  30. #include <clib/exec_protos.h>
  31. #include <clib/intuition_protos.h>
  32. #include <clib/gadtools_protos.h>
  33. #include <clib/graphics_protos.h>
  34. #include <clib/utility_protos.h>
  35. #include <string.h>
  36. #include <pragmas/exec_pragmas.h>
  37. #include <pragmas/intuition_pragmas.h>
  38. #include <pragmas/gadtools_pragmas.h>
  39. #include <pragmas/graphics_pragmas.h>
  40. #include <pragmas/utility_pragmas.h>
  41. #include <proto/textfield.h>
  42.  
  43. #include "dbGUI.h"
  44. #include "db.h"
  45. #include "dbparser.h"
  46. #include "Version.h"
  47.  
  48.  
  49. #define TOGGLE_LED *(UBYTE *)0xbfe001 ^= 2
  50.  
  51. extern Class *TextFieldClass;
  52. extern struct IFFHandle *Iff0;
  53.  
  54. struct Screen         *Scr = NULL;
  55. struct DrawInfo *DrInfo = NULL;
  56. UWORD *Pens;
  57. APTR                   VisualInfo = NULL;
  58. struct IntuiMessage    DB_Msg;
  59. UWORD                  DB_Zoom[4];
  60. struct Gadget          *LastGad = NULL;
  61. struct Hook                                     MyStrHook;
  62. struct TextAttr       *Font, Attr;
  63. UWORD                  FontX, FontY;
  64. UWORD                  OffX, OffY;
  65. UWORD                  DragKnobWidth, DragKnobHeight;
  66.  
  67. WORD LastLeftEdge=-1;
  68. WORD LastTopEdge=-1;                                    /* For nice layoutswitching */
  69.  
  70. /*For gadgetlayout */
  71. UWORD TabSize;
  72.  
  73. /* For MyStrHookFunc() */
  74. BOOL ReactivateGad = FALSE;
  75. BOOL GadDoubleClicked = FALSE;
  76. struct Gadget *NextGad = NULL;
  77.  
  78. struct TextAttr UserTextAttr =
  79. {
  80.         NULL, 0, FS_NORMAL, FPF_DISKFONT
  81. };
  82.  
  83.  
  84. struct NewMenu DB_NewMenu[] = {
  85.         NM_TITLE, (STRPTR)MSG_PROJECT_MENU , NULL, 0, NULL, NULL,
  86.         NM_ITEM, (STRPTR)MSG_PROJECT_NEW   , NULL, 0, 0L,   (APTR)DB_NEW,
  87.         NM_ITEM, (STRPTR)MSG_PROJECT_OPEN  , NULL, 0, 0L,   (APTR)DB_OPEN,
  88.         NM_ITEM, (STRPTR)MSG_PROJECT_RELOAD, NULL, 0, 0L,   (APTR)DB_RELOAD,
  89.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  90.         NM_ITEM, (STRPTR)MSG_PROJECT_SAVE   , NULL, 0, 0L,  (APTR)DB_SAVE,
  91.         NM_ITEM, (STRPTR)MSG_PROJECT_SAVE_AS, NULL, 0, 0L,  (APTR)DB_SAVEAS,
  92.         NM_ITEM, (STRPTR)MSG_PROJECT_OUTPUT , NULL, 0, NULL,NULL,
  93.         NM_SUB, (STRPTR)MSG_PROJECT_OUTPUT_VIEW, NULL, 0, 0L, (APTR)DB_OUTPUT_VIEW,
  94.         NM_SUB, (STRPTR)MSG_PROJECT_OUTPUT_VIEW_WN, NULL, 0, 0L, (APTR)DB_OUTPUT_VIEW_WN,
  95.         NM_SUB, (STRPTR)MSG_PROJECT_OUTPUT_TAB_ASCII, NULL, 0, 0L, (APTR)DB_OUTPUT_TAB_ASCII,
  96.         NM_SUB, (STRPTR)MSG_PROJECT_OUTPUT_COMMA_ASCII, NULL, 0, 0L, (APTR)DB_OUTPUT_COMMA_ASCII,
  97.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  98.         NM_ITEM, (STRPTR)MSG_PROJECT_ABOUT, NULL, 0, 0L, (APTR)DB_ABOUT,
  99.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  100.         NM_ITEM, (STRPTR)MSG_PROJECT_QUIT, NULL, 0, 0L, (APTR)DB_QUIT,
  101.         NM_TITLE, (STRPTR)MSG_EDIT_MENU, NULL, 0, NULL, NULL,
  102.         NM_ITEM, (STRPTR)MSG_EDIT_CUT, NULL, 0, 0L, (APTR)DB_CUT,
  103.         NM_ITEM, (STRPTR)MSG_EDIT_COPY, NULL, 0, 0L, (APTR)DB_COPY,
  104.         NM_ITEM, (STRPTR)MSG_EDIT_PASTE, NULL, 0, 0L, (APTR)DB_PASTE,
  105.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  106.         NM_ITEM, (STRPTR)MSG_EDIT_ADD, NULL, 0, 0L, (APTR)DB_ADD,
  107.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  108.         NM_ITEM, (STRPTR)MSG_EDIT_KILL, NULL, 0, 0L, (APTR)DB_KILL,
  109.         NM_TITLE, (STRPTR)MSG_VIEW_MENU, NULL, 0, NULL, NULL,
  110.         NM_TITLE, (STRPTR)MSG_ACTION_MENU, NULL, 0, NULL, NULL,
  111.         NM_ITEM, (STRPTR)MSG_ACTION_FIND, NULL, 0, 0L, (APTR)DB_FIND,
  112.         NM_ITEM, (STRPTR)MSG_ACTION_FIND_NEXT, NULL, 0, 0L, (APTR)DB_FINDNEXT,
  113.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  114.         NM_ITEM, (STRPTR)MSG_ACTION_SORT, NULL, 0, 0L, (APTR)DB_SORT,
  115.         NM_ITEM, (STRPTR)MSG_ACTION_DIAL, NULL, 0, 0L, (APTR)DB_DIAL,
  116.         NM_ITEM, (STRPTR)MSG_ACTION_BROWSE, NULL, 0, 0L, (APTR)DB_BROWSE,
  117.         NM_TITLE, (STRPTR)MSG_SETTINGS_MENU, NULL, 0, NULL, NULL,
  118.         NM_ITEM, (STRPTR)MSG_SETTINGS_WARNINGS, NULL, CHECKIT|CHECKED|MENUTOGGLE, 0L, (APTR)DB_WARNINGS,
  119.         NM_ITEM, (STRPTR)MSG_SETTINGS_SORTDIR, NULL, 0, NULL, NULL,
  120.         NM_SUB, (STRPTR)MSG_SETTINGS_SORTDIR_AZ, NULL, CHECKIT|CHECKED, 2L, (APTR)DB_AZ,
  121.         NM_SUB, (STRPTR)MSG_SETTINGS_SORTDIR_ZA, NULL, CHECKIT, 1L, (APTR)DB_ZA,
  122.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  123.         NM_ITEM, (STRPTR)MSG_SETTINGS_FIELD_DEFINITION, NULL, NM_ITEMDISABLED, 0L, (APTR)DB_FIELD_DEFINITION,
  124.         NM_ITEM, (STRPTR)MSG_SETTINGS_VIEW_DESIGN, NULL, 0L, 0L, (APTR)DB_VIEW_DESIGN,
  125.         NM_TITLE, (STRPTR)MSG_AREXX_MENU, NULL, 0, NULL, NULL,
  126.         NM_ITEM, (STRPTR)MSG_AREXX_EXECUTE, NULL, 0, 0L, (APTR)DB_EXECUTE_AREXX,
  127.         NM_ITEM, (STRPTR)MSG_AREXX_EXECUTE_RELAUNCH, NULL, 0, 0L, (APTR)DB_EXECUTE_AREXX_AGAIN,
  128.         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  129.         NM_END, NULL, NULL, 0, 0L, NULL };
  130.  
  131.  
  132. void LocalizeMenu(struct NewMenu *nm)
  133. {
  134.         /* Replaces the string-indexes in the NewMenu array with localized text */
  135.         /* Gets called once from SetupScreen() */
  136.         UWORD   i=0;
  137.  
  138.         while (nm[i].nm_Type != NM_END) {
  139.                 if (nm[i].nm_Label != NM_BARLABEL) {
  140.                         nm[i].nm_CommKey = GetAppStr((LONG)nm[i].nm_Label);
  141.  
  142.                         nm[i].nm_Label = nm[i].nm_CommKey+2;
  143.                         if (nm[i].nm_CommKey[0] == ' ') nm[i].nm_CommKey = NULL;
  144.                 }
  145.         ++i;
  146.         }
  147. }
  148. /**/
  149. __inline BOOL OkStrGad(struct Gadget *g)
  150. {
  151.         return (BOOL)(g->Flags & GFLG_TABCYCLE && !(g->Flags & GFLG_DISABLED));
  152. }
  153.  
  154. struct Gadget *PrevStrGad(struct Gadget *Gad, struct Gadget *glist)
  155. {
  156.         /* Returns the previous stringgadget, or NULL if Gad is the first one */
  157.  
  158.         struct Gadget *strgad = NULL, *g = glist;
  159.  
  160.         if (g == Gad) return NULL;
  161.         for (; g; g = g->NextGadget) {
  162.                 if (OkStrGad(g)) strgad = g;    /* Only return stringgads */
  163.                 if (g->NextGadget == Gad) break;
  164.         }
  165.         return strgad;
  166. }
  167.  
  168. struct Gadget *EndGad(struct Gadget *g)
  169. {
  170.         while (g->NextGadget) g = g->NextGadget;
  171.         return g;
  172. }
  173.  
  174. struct Gadget *ActivateThisGad(ULONG actions, struct Gadget *current,
  175.  struct Gadget *glist)
  176. {
  177.         /* Takes over the job of deciding which (if any) gadget should be reactivated
  178.          * based upon the SGWork->Actionfield.
  179.          * Without this function, it is impossible to activate other stringgadgets
  180.          * (as responce to an ARexx command) as Intiuition otherwize will have
  181.          * activated some other gadget first if the user cyclesteps thru a gadgetlist.
  182.     */
  183.         struct Gadget *g = NULL;
  184.  
  185.         if (actions & SGA_NEXTACTIVE) {
  186.                 for (g = current->NextGadget;; g = g->NextGadget) {
  187.                         if (!g) g = glist;
  188.                         if (OkStrGad(g)) break;
  189.                 }
  190.         }
  191.         else if (actions & SGA_PREVACTIVE) {
  192.                 for (g = PrevStrGad(current, glist);; g = PrevStrGad(g, glist)) {
  193.                         if (!g) g = EndGad(glist);
  194.                         if (OkStrGad(g)) break;
  195.                 }
  196.         }
  197.         return g;
  198. }
  199.  
  200.  
  201. /* Stuff for my stringHook */
  202.  
  203. ULONG __saveds __asm MyStrHookFunc(register __a0 struct Hook *hook,
  204.                                                                                           register __a2 struct SGWork *sgw,
  205.